<layout name="layout"/>

<div class="main-div">


    <form name="main_form" class="form-x" id="myform" method="POST" action="__SELF__" enctype="multipart/form-data">
        <input type="hidden" name="id" value="<?php echo $data['id']; ?>"/>
        <div class="form-group">
            <div class="label">
                <label>用户名：</label>
            </div>
            <div class="field">
                <input type="text" class="input w50" value="<?php echo $data['username']; ?>" name="username"
                       data-validate="required:用户名称"/>
                <div class="tips"></div>
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                <label>手机号：</label>
            </div>
            <div class="field">
                <input type="text" class="input w50" onblur="isPoneAvailable(this.value)"
                       value="<?php echo $data['phone']; ?>" name="phone"
                       data-validate="required:手机号"/>
                <div class="tips"></div>
            </div>
        </div>


        <div class="form-group">
            <div class="label">
                <label>所属代理编号：</label>
            </div>
            <div class="field">
                <input type="text" class="input w50"
                       value="<?php echo $data['domain']; ?>" readonly name="domain"
                       data-validate="required:所属代理编号"/>
                <div class="tips"></div>
            </div>
        </div>
        <div class="form-group">
            <div class="label">
                <label></label>
            </div>
            <div class="field">
                <input type="button" value="提交" id="submit" class="button bg-blue">
                <input type="reset" value="重置" class="button bg-red">
                <input type="button" value="取消" onclick="javascript :history.back(-1)" class="button bg-main">
            </div>
        </div>
    </form>
</div>
<script>
    $("#submit").click(function () {
        var data = $("#myform").serialize();
        if ($("input[name='username']").val() == '' || $("input[name='username']").val() == undefined) {
            alert('用户名不能为空');
            return false;
        }
        if ($("input[name='phone']").val() == '' || $("input[name='phone']").val() == undefined) {
            alert('手机号不能为空');
            return false;
        }

        $.post("<?php echo U('edit')?>", data, function (res) {

            alert(res.info);
            location.href = res.url;
        })
    })

    function isPoneAvailable(poneInput) {

        var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
        if (!myreg.test(poneInput)) {
            alert('手机号码不正确！');
            return false;
        }
    }
</script>
